/**
 * @author wangj881
 * @date 2024-12-26 10:39
 */
public class L11_3 {

    public static void main(String[] args) {
        int[] height = {1, 8, 6, 2, 5, 4, 8, 3, 7};
        int maxArea = new Solution().maxArea(height);
        System.out.println(maxArea);

    }

    static class Solution {
        public int maxArea(int[] height) {
            int left = 0;
            int right = height.length - 1;
            int result = 0;
            while (left < right) {
                result = Math.max(result, (right - left) * Math.min(height[left], height[right]));
                if (height[left] <= height[right]) {
                    left++;
                } else {
                    right--;
                }
            }
            return result;
        }
    }
}
